<?php
// create a dom object
$this->xml = new DOMDocument("1.0");
// create root element 'rsp'
$this->rsp = $this->xml->createElement("rsp");
// add the 'rsp' element to the xml document
$this->xml->appendChild($this->rsp);

$cocktailsXML = $this->xml->createElement('cocktails');
if(is_array($this->cocktails)){
	foreach ($this->cocktails as $cocktail){
		$cocktail->toXml($this->xml,$cocktailsXML);
	}
}
// set count for recipe element according to number of recipes found
$cocktailsXML->setAttribute('count',count($this->cocktails));
// add the '$recipes' element to the 'rsp' element
$this->rsp->appendChild($cocktailsXML);
// set status for root element 'rsp' to 'ok'
$this->rsp->setAttribute('status','ok');

// save and display tree
print $this->xml->saveXML();
